var app = getApp();
Page({
    data:{
        curPage : "/zofui_sales/fenxiao/user",
        Menu: [{
            url: "/zofui_sales/pages/index/index",
            iconPath: "https://img11.360buyimg.com/ddimg/jfs/t1/66538/19/4014/3269/5d2351f9E53638303/d16ba3ba1f225e55.png",
            selectedIconPath: "https://img11.360buyimg.com/ddimg/jfs/t1/66538/19/4014/3269/5d2351f9E53638303/d16ba3ba1f225e55.png",
            title: "首页",
            type: "tabbar"
        }, {
            url: "/zofui_sales/fenxiao/goods",
            iconPath: "https://img11.360buyimg.com/ddimg/jfs/t1/76564/29/4072/4005/5d235934E9e4fec12/485ebe5e6f2b173f.png",
            selectedIconPath: "https://img11.360buyimg.com/ddimg/jfs/t1/53034/40/4498/4044/5d235938E08362533/0b26e6d2c077df6b.png",
            title: "销售"
        }, {
            url: "/zofui_sales/fenxiao/bill",
            iconPath: "https://img11.360buyimg.com/ddimg/jfs/t1/49710/34/4519/3981/5d235a12E2cc284ad/a4a02c22c99b4b61.png",
            selectedIconPath: "https://img11.360buyimg.com/ddimg/jfs/t1/34162/25/14452/4622/5d235a15E1e64565f/3900800ba49583a9.png",
            title: "资金",
        }, {
            url: "/zofui_sales/fenxiao/user",
            iconPath: "https://img11.360buyimg.com/ddimg/jfs/t1/45769/18/4567/6267/5d235b21Efff10c3e/507efc3f920d8740.png",
            selectedIconPath: "https://img11.360buyimg.com/ddimg/jfs/t1/72323/28/3988/6330/5d235b25E127fda9d/ecbb0c9f41cf8633.png",
            title: "结算中心"
        }],
        isIPX : app.globalData.isIPX,
		siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
    },
    onLoad:function(options){
        var self = this;
        var zfid = options.zfid ? options.zfid : '';
        self.setData({
            options : options,
        });
        app.com.auth(function(user){
            app.com.http('fenxiao','POST',{zfid:zfid,op:'user'},0,false,'','',function(res){
                if (!res.data.errno) {
                    self.setData({
                        Pagetheme : res.data.data.params.style,
                        userinfo : res.data.data.userinfo,
                        dataInfo : res.data.data.datainfo,
                        params : res.data.data.params,
                        sharedata : res.data.data.sharedata,
                        inited : true,
                    });
                    
                    if( res.data.data.params.pfs == 1 && self.data.Menu.length >= 4 ){
                        self.data.Menu.splice(1,1);
                    }
                    
                    self.setData({
                        Menu : self.data.Menu
                    })


                }else if( res.data.errno == 3 ){
                    app.com.confirm(res.data.message,function(){
                        var tourl = '/zofui_sales/ucard/buycard';
                        wx.navigateTo({
                          url: tourl
                        });
                        self.setData({
                            reload : 1,
                        });
                    },function(){
                         var pages = getCurrentPages();
                         if( pages.length > 1 ){
                            wx.navigateBack();
                         }else{
                            var tourl = '/zofui_sales/pages/index/index?zfid='+options.zfid;
                            wx.switchTab({
                              url: tourl
                            });
                         }
                    },'取消','购买会员');
                }else if( res.data.errno == 4 ){
                    app.com.alert(res.data.message,function(){
                        var tourl = '/zofui_sales/fenxiao/joinPartner';
                        wx.navigateTo({
                          url: tourl
                        });
                    })
                }else{
                    app.com.alert(res.data.message);
                }
            });
        });
        wx.setNavigationBarTitle({
          title:  '结算中心',
        });
    },
    onShow(){
        var self = this;
        if( this.data.reload == 1 ){
            self.onLoad(self.data.options);  
            self.setData({
                reload : 0,
            });
        }
    },
    getPoster(){
        var self = this;
        app.com.http('poster','POST',{op:'user'},0,true,'','',function(res){
            if (!res.data.errno && res.data ) {
                wx.previewImage({
                    urls : [res.data.data.url]
                })
            }else{
                app.com.alert(res.data.message);
            }
        });
    },
    onShareAppMessage : function(){
        var self = this;
        return {
            title: self.data.sharedata.title,
            path: self.data.sharedata.path,
            imageUrl : self.data.sharedata.img,
        }
    },
    onPullDownRefresh: function () {
        if( this.data.isdown ) return false;
        this.data.isdown = true;
        
        this.onLoad( this.data.options );
        this.data.isdown = false;
        // 关闭下拉刷新
        wx.stopPullDownRefresh();
    },
    location : function( e ){
        app.com.location( e );
    },
    copy(){
        var self = this;
        wx.setClipboardData({
            data: self.data.userinfo.agentcode,
            success : function (res) {
                
            }
        })
    },
    navigateto : function( e ){
        app.com.navigateto( e );
    },
    redirectto : function( e ){
        app.com.redirectto( e );
    },    
    callphone : function(e){
        app.com.callphone( e );
    },
    toweburl : function(e){
        app.com.toweburl( e );
    },
    showimages : function( e ){
        app.com.showimages(e);
    },
    footNavigate(e){
        var url = e.currentTarget.dataset.url;
        wx.switchTab({
          url: url
        })
    },

})